package cn.softeem.tushu.po;

import java.math.BigDecimal;

public class Cartitem {
    //    alter table `t_cartitem` add CONSTRAINT `FK_t_cartitem_t_book` FOREIGN KEY (`bid`) REFERENCES `t_book` (`bid`)
//    alter table `t_cartitem` add CONSTRAINT `FK_t_cartitem_t_user` FOREIGN KEY (`uid`) REFERENCES `t_user` (`uid`)
//    CREATE TABLE `t_cartitem` (
//            `cartItemId` char(32) NOT NULL,
//  `quantity` int(11) DEFAULT NULL,
//  `bid` char(32) DEFAULT NULL,
//  `uid` char(32) DEFAULT NULL,
//  `orderBy` int(11) NOT NULL AUTO_INCREMENT,
//    PRIMARY KEY (`cartItemId`),
//    KEY `orderBy` (`orderBy`),
//    KEY `FK_t_cartitem_t_user` (`uid`),
//    KEY `FK_t_cartitem_t_book` (`bid`)
//            ) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;
    private String cartItemId;
    private Integer quantity;
    private Integer orderBy;
    private Book book;
    private User user;


    public String getCartItemId() {
        return cartItemId;
    }

    public void setCartItemId(String cartItemId) {
        this.cartItemId = cartItemId;
    }

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    public void setOrderBy(Integer orderBy) {
        this.orderBy = orderBy;
    }

    public Book getBook() {
        return book;
    }

    public void setBook(Book book) {
        this.book = book;
    }

    public double getSubtotal() {
        BigDecimal v1 = new BigDecimal(Double.toString(book.getCurrPrice()));
        BigDecimal v2 = new BigDecimal(Double.toString(quantity));
        return v1.multiply(v2).doubleValue();
    }

    public Integer getOrderBy() {
        return orderBy;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public String toString() {
        return "Cartitem{" +
                "cartItemId='" + cartItemId + '\'' +
                ", quantity=" + quantity +
                ", orderBy=" + orderBy +
                ", book=" + book +
                '}';
    }
}
